<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="common/include :: header('修养预约列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<!--模块一,用于数据的高级查询-->
			<div class="col-sm-12 search-collapse">
				<form id="serviceItem-form">
					<div class="select-list">
						<ul>
							<li>
								客户姓名：<input type="text" name="customerName"/>
							</li>
							<li>
								联系方式：<input type="text" name="customerPhone"/>
							</li>
							<li>
								状态：
								<select name="status" th:with="type=${@dict.getType('cmi_status')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<!--模块二,新增,修改,删除,导出的四个按钮-->
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:serviceItem:add">
	                <i class="fa fa-plus"></i> 添加
	            </a>
	        </div>

			<!--表格模块,使用了异步刷新的前端框架bootstrap-table-->
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="common/include :: footer" />
	<script th:inline="javascript">
		var serviceTypeDates = [[${@dict.getType('cmi_service_type')}]];
		 var statusDates = [[${@dict.getType('cmi_status')}]];
		var prefix = ctx + "/business/appointment";
		$(function() {
		    var options = {
		        url: prefix + "/query",						//查询的url路径
		        createUrl: prefix + "/addPage",				//新增的url
		        updateUrl: prefix + "/editPage?id={id}",	//编辑的url 携带了id
		        exportUrl: prefix + "/export",				//导入的url
				removeUrl: prefix + "/remove",
				sortName: "seq",
				modalName: "修养预约",
		        columns: [{
		            checkbox: true						//在表格前面加入了复选框
		        },
		        {
		            field: 'id',
		            title: '修养预约id',
					visible: false						//设为false表示隐藏id列,在页面上不做显示
		        },
		        {
		            field: 'customerName',
		            title: '客户姓名',
		            sortable: true
		        },
					{
						field: 'customerPhone',
						title: '联系方式',
						sortable: true
					},
					{
						field: 'appointmentTime',
						title: '预约时间',
						sortable: true
					},
					{
						field: 'actualArrivalTime',
						title: '实际到店时间',
						sortable: true,
					},

				{
					field: 'licensePlate',
					title: '车牌号',
					sortable: true,
				},
				{
					field: 'carSeries',
					title: '汽车类型',
					sortable: true,
				},
				{
					field: 'serviceType',
					title: '服务类型',
					sortable: true,
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(serviceTypeDates, value);
					}
				},
				{
					field: 'info',
					title: '备注信息',
					sortable: true,
				},

				{
					field: 'status',
					title: '状态',
					sortable: true,
						formatter: function(value, row, index) {
							return $.table.selectDictLabel(statusDates, value);
						}
					},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
						//判断如果不是预约中的状态不允许编辑
						var editClass = row.status === 0 ? '' : 'disabled';
						var arralClass = row.status === 0 ? '' : 'disabled';
						var cancelClass = row.status === 0 ? '' : 'disabled';
						var deleteClass = row.status === 0 ? '' : 'disabled';
						var consumeClass = row.status === 1 || row.status === 4 ? '' : 'disabled';
						var actions = [];
						actions.push('<a class="btn btn-success btn-xs '+ editClass +'" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-warning btn-xs '+ arralClass +'" href="javascript:void(0)" onclick="arralShow(\'' + row.id + '\')"><i class="fa fa-remove"></i>到店</a> ');
						actions.push('<a class="btn btn-info btn-xs '+ consumeClass +'" href="javascript:void(0)" onclick="generateConsume(\'' + row.id + '\')"><i class="fa fa-remove"></i>结算单</a> ');
						var more = [];
						more.push("<a class='btn btn-default btn-xs "+ deleteClass +"' href='javascript:void(0)' onclick='$.operate.remove(" + row.id + ")'><i class='fa fa-check-square-o'></i>删除</a> ");
						more.push("<a class='btn btn-default btn-xs " + cancelClass + "' href='javascript:void(0)' onclick='cancel(" + row.id + ")'><i class='fa fa-user'></i>取消订单</a>");
						actions.push('<a tabindex="0" class="btn btn-primary btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true"' +
								' data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
						return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});

		function generateConsume(id) {
			//弹出模态框
			$.modal.confirm("确定要结算吗?" , function() {
				//发送ajax请求,带上服务单的id到后端
				$.operate.get("/business/appointment/generateConsume?id=" + id , function (data) {
					//回调函数
					$.modal.openTab("明细界面","/business/statementItem/itemDetail?statementId=" + data.data);
				});
			})
		}

		function arralShow(id) {
			$.modal.confirm("确定要改为到店吗", function() {
				$.operate.get('/business/appointment/arralShow?id='+ id);
			});
		}
		function cancel(id) {
			$.modal.confirm("确定要取消吗?", function() {
				$.operate.get('/business/appointment/cancel?id='+ id);
			});
		}
	</script>
</body>
</html>